package cn.zhouchao.basic.controller;

import cn.zhouchao.basic.dto.SmsCodeDto;
import cn.zhouchao.basic.service.VerifyCodeService;
import cn.zhouchao.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private VerifyCodeService verifyCodeService;

    /**
     * 获取图形验证码
     */
    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult graph(@PathVariable("imageCodeKey") String redisKey) throws IOException {
        String base64Graph =  verifyCodeService.graph(redisKey);
        return AjaxResult.me().success(base64Graph);
    }

    /**
     * @PathVariable 带有参数的请求注解
     * @RequestBody 整个对象的请求注解
     */

    /**
     * 获取手机验证码
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody SmsCodeDto dto) {
        verifyCodeService.smsCode(dto);
        return AjaxResult.me().success();
    }
}

